<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>个人页面</title>
  <script src="https://cdn.jsdelivr.net/npm/babel-polyfill/dist/polyfill.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/jquery"></script>
  <script src="__PUBLIC__/node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
  <script src="__PUBLIC__/node_modules/datatables/media/js/jquery.dataTables.min.js"></script>
  <link rel="stylesheet" href="__PUBLIC__/node_modules/bootstrap/dist/css/bootstrap.min.css">
  <link rel="stylesheet" href="__PUBLIC__/style/manage.css">
  <link rel="stylesheet" href="__PUBLIC__/style/me.css">
  <!-- 弹层 -->
  <script src="__PUBLIC__/script/layer/layer.js"></script>
</head>
<body>
  <!-- 隐藏功能元素区 -->
  <div class="hidden_form">
    <form autocomplete="off" action="{:U('manage_me_chanpin')}" method="get" id = 'hidden_form'></form>
    <input type="hidden" name="添加商品别名" id='add_goods_nick_name' value="{:U('Manageme/add_goods_nick_name')}">
    <input type="hidden" name="更新商品别名" id='update_goods_nick_name' value="{:U('Manageme/update_goods_nick_name')}">
  </div>
  <!-- end 隐藏功能元素区 -->

  <div class="container-fluid">
    <div class="col-xs-12" style="height:5px;"></div>
    <div class="col-xs-11 col-xs-offset-1">
      <!-- Nav tabs -->
      <iframe src="{:U('me')}?local=chanpin" frameborder="0" style="width:100%;"></iframe>
    </div>

    <div class="main">
      <!-- logo 区域 -->
      <div class="logo_img">
        <if condition="$Think.session.user.login_img neq null">
        <span><img src="__ROOT__/{$Think.session.user.login_img}" alt="LOGO"></span>
        <else/>
        <span><img src="__PUBLIC__/images/dengluye/u5.png" alt="u5"></span>
        </if>
        <br>
        <span>{$Think.session.user.u_name}</span>
      </div>
      <!-- end logo 区域 -->

      <!-- 筛选区 -->
      <div class="search_form col-xs-offset-1 col-xs-10">
        <div class="ol_search_form_container"><span><img src="__PUBLIC__/images/dengluye/u391.png" alt="u391"></span> <input form="hidden_form" name= 'search' type="text" placeholder="产品名称" class="search_form" id='search_input'><input form="hidden_form" type="submit" value="搜索" class="search_button"></div>
        <div class="ol_search_button">
            <a class="only_one_type"><input checked style='display:none;' type="radio" name='qudao_type' value="0" id='qudao_type_1' form='hidden_form'><label for="qudao_type_1">全部渠道</label></a>
            <a class="only_one_type"><input style='display:none;' type="radio" name='qudao_type' value="1" id='qudao_type_2' form='hidden_form'><label for="qudao_type_2">银行</label></a>
            <a class="only_one_type"><input style='display:none;' type="radio" name='qudao_type' value="2" id='qudao_type_3' form='hidden_form'><label for="qudao_type_3">消费金融</label></a>
            <a class="only_one_type"><input style='display:none;' type="radio" name='qudao_type' value="3" id='qudao_type_4' form='hidden_form'><label for="qudao_type_4">小额</label></a>
            <a class="only_one_type"><input style='display:none;' type="radio" name='qudao_type' value="4" id='qudao_type_5' form='hidden_form'><label for="qudao_type_5">其他</label></a>
        </div>
        <div class="ol_search_button">
            <a class="only_one_type"><input checked style='display:none;' type="radio" name='chanpin_type' value='0' id='chanpin_type_0' form='hidden_form'><label for="chanpin_type_0">产品类型</label></a>
            <volist name='goods_type' id='types'>
            <a class="only_one_type"><input style='display:none;' type="radio" name='chanpin_type' value="{$types}" id="chanpin_type_{$key+1}" form='hidden_form'><label for="chanpin_type_{$key+1}">{$types}</label></a>
            </volist>
        </div>
<!--         <div class="ol_search_button">
            <a class="only_one_type"><input checked style='display:none;' type="radio" name='chanpin_tag' value='0' id='chanpin_tag_0' form='hidden_form'><label for="chanpin_tag_0">产品标签</label></a>
            <a class="only_one_type"><input style='display:none;' type="radio" name='chanpin_tag' value='1' id='chanpin_tag_1' form='hidden_form'><label for="chanpin_tag_1">月供带</label></a>
            <a class="only_one_type"><input style='display:none;' type="radio" name='chanpin_tag' value='2' id='chanpin_tag_2' form='hidden_form'><label for="chanpin_tag_2">工薪贷</label></a>
        </div> -->
      </div>
      <!-- end 筛选区 -->

      <!-- 表头 -->
      <div class="col-xs-offset-1 col-xs-10 table_title">
        <span>已有系统产品</span>
        <!-- <img title = '添加渠道' id = 'images/dengluye/u80.png' src="__PUBLIC__/images/dengluye/u80.png" alt="u80"> -->
      </div>
      <!-- end 表头 -->

      <!-- 表格区 -->
      <div class="col-xs-offset-1 col-xs-10">
        <table class="messageBoxContent table table-striped table-bordered" id="main_table">
          <thead>
            <tr>
              <th class="No" style='min-width:5rem;'>序号</th>
              <th class="Date">加盟时间</th>
              <th class="qudao_type">渠道类型</th>
              <th class="chanpin_type">产品类型</th>
              <th class="chanpin_name">产品名称</th>
              <th class="chanpin_nick_name" style='min-width:100px;'>自定义名称</th>
              <th class="qudao_name">适用渠道</th>
              <th class="fangkuan">放款形式</th>
              <th class="Modify">更多</th>
            </tr>
          </thead>
          <tbody>
            <volist name='list' id='vo'>
            <tr>
                <td class="No" inori-id='{$vo.id}'>{$key+1}</td>
                <td class="Date">{$vo.timeda}</td>
                <td class="qudao_type">{$vo.qudao_type}</td>
                <td class="chanpin_type"><span>{$vo.name}</span></td>
                <td class="chanpin_name">{$vo.litter_name}</td>
                <th class="chanpin_nick_name" inori-data='{$vo.nick_id}'>{$vo.id|re_diy_nick}</th>
                <td class="qudao_name">{$vo.qudaoname}</td>
                <td class="fangkuan">{$vo.lendingfangshi}</td>
                <td class="Modify">
                  <a href='javascript:;' onclick="settingThisLine(this, event)"><img title='设置' src="__PUBLIC__/images/dengluye/u41.png" alt="u41"></a>
                  <!-- <a href='javascript:;' onclick="delThisLine(this, event)"><img title='删除' src="__PUBLIC__/images/dengluye/u566.png" alt="u566"></a> -->
                </td>
            </tr>
            </volist>
          </tbody>
        </table>

        <!-- begin 分页 -->
        <div class="authPage">
          <!-- 页面指示器 -->
          <!-- <div class="pages">24/{$count}</div> -->
          <!-- 分页列表 -->
          <!-- <span class="number">...</span> -->
          <div class="pageJump">
            {$page}
          </div>
        </div>
        <!-- end 分页 -->
      </div>
      <!-- end 表格区 -->

    </div>

    <!-- 页脚 -->
    <div class="col-xs-12">
      <div class="footer text-center"><p class="lead"><strong>深圳市東源匯信息科技有限公司</strong></p></div>
    </div>
    <!-- end 页脚 -->
  </div>

  <script>
    $(document).ready(function () {
      var proList = $('#main_table').DataTable({
        "paging": false,
        "info": false,
        "searching": false
      })
    })
    function settingThisLine (_this, evt) {
      layer.msg(`修改后点击空白区域提交修改`)
      const parentEle = $(_this).closest('tr')
      const textValue = parentEle.find('.chanpin_nick_name').text()
      parentEle.find('.chanpin_nick_name').text(null).append(`<input type='text'>`)
      parentEle.find(`.chanpin_nick_name input[type='text']`).val(textValue)
      parentEle.find(`.chanpin_nick_name input[type='text']`).on('blur', (evt) => {
        layer.msg(`正在提交本条数据`)
        const parentEle = $(evt.target).closest('tr')
        const value = parentEle.find(`.chanpin_nick_name input[type='text']`).val()
        const addURL = String($(`#add_goods_nick_name`).val())
        const updateURL = String($(`#update_goods_nick_name`).val())
        let ajaxURL = addURL
        let AjaxData = {
          g_id: parentEle.find(`.No`).attr(`inori-id`),
          nick_name: $(evt.target).val()
        }
        if (parentEle.find(`.chanpin_nick_name`).attr('inori-data') !== '') {
          ajaxURL = updateURL
          AjaxData.nick_id = parentEle.find(`.chanpin_nick_name`).attr('inori-data')
        }
        $.ajax(ajaxURL, {
          method: 'post',
          data: AjaxData,
          beforeSend: () => {
            layer.msg(`正在发送该条数据`)
          }
        }).fail((err) => {
          layer.closeAll()
          alert(`通信失败，请检查网络`)
          throw new Error(`通信失败，请检查网络`)
        }).done((res) => {
          layer.closeAll()
          if (String(res.code) === '1' || String(res.code) === '2') {
            parentEle.find('.chanpin_nick_name').text(null).text(value)
            if (res.nick_id) parentEle.find(`.chanpin_nick_name`).attr('inori-data', `${res.nick_id}`)
          } else {
            alert(`服务器响应失败： ${res.message}`)
            throw new Error(`服务器响应失败： ${res.message}`)
          }
        })
      })
    }
    function delThisLine (_this, evt) {
      //
    }
    // 提交动作
    function submitHandler (evt) {
      evt.preventDefault()
      // 如果搜索栏为空，就全部结果
      if (String($('#search_input').val()).replace(/\s/g, '') === '' && $('#qudao_type_1').prop('checked') === true && $('#chanpin_type_0').prop('checked') === true && $('#chanpin_tag_0').prop('checked') === true) {
        location.href = `{:U('manage_me_chanpin')}`
      } else {
        // $('#search_input').val(`${$('#search_input').val()}`)
        $('#hidden_form').submit()
      }
    }
    $('.search_button').on({click: submitHandler}, {})
  </script>
</body>
</html>